package com.zzh.oauth.controller;

import java.security.Principal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private ConsumerTokenServices consumerTokenServices;

    /**
     * 资源服务器提供的受保护接口
     *
     * @param principal
     * @return
     */
    @RequestMapping("/user")
    public Principal user(Principal principal) {
        System.out.println(principal);
        return principal;
    }

    /**
     * 退出登录
     * @param token
     * @return
     */
    @RequestMapping("/exit")
    public boolean exit(@RequestParam("token")String token) {
        boolean b = consumerTokenServices.revokeToken(token);
        return b;
    }

}
